<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/taglib_include.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, target-densitydpi=medium-dpi, initial-scale=0.5, minimum-scale=0.5, maximum-scale=0.5, user-scalable=no" />
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta content="black" name="apple-mobile-web-app-status-bar-style" />
<meta content="telephone=no" name="format-detection" />
<link href="${ctx}/css/layout.css?ver=${layout_css_version}" rel="stylesheet" type="text/css" />
<style type="text/css">
.b-font {
	width: 90%;
	margin: 10pt auto 0px;
}

#s-information {
	height: auto !important;
	height: 120pt;
	min-height: 120pt;
}

input[type="checkbox"] {
	-webkit-appearance: none;
	-moz-appearance: none;
	appearance: none;
	height: 46px;
	vertical-align: middle;
	width: 46px;
	border-style: solid;
	border-width: 1px;
	border-radius: 8px;
}

input[type="checkbox"]:checked {
	background-image: url(../images/Check-select-lightblue.png);
	background-position: 0 0;
	background-color: white;
	border-style: none;
}

.serviceprice {
	border: none;
	clear: both;
	width: 100%;
	display: block;
	overflow: hidden;
	height: 25pt;
	line-height: 25pt;
	border-bottom: none;
	/*     padding: 4pt 0pt 0pt 0pt; */
	margin: -1pt;
	float: left;
	background: #fff;
}

.totprices {
	margin-right: 3%;
	float: right;
}

#w-bg, #total-price {
	border-top: 0px solid #b2b2b2;
}

#Nticket-tip-1 > a {
	color: #FF4500;
	text-decoration: underline;
    display: initial;
}

#Nticket-tip-1 {
	height: 38pt;
    margin-left:5%;
}
</style>
<title>${projectTitle }</title>
</head>
<body>
  <header id="main-top">
    <a href="${ticketQueryURL }">
      <div id="main-top-left">
        <img src="${ctx}/images/mui_title_back_btn.png" class="img-2">
      </div>
    </a>
    <div id="main-top-title">确认订单</div>
    <a id="main-top-right" href="javascript:void(0);">
      <img src="${ctx }/images/home_icon.png">
    </a>
  </header>
  <form action="" method="post" id="form">
  <div id="container">
      <div class="f-information">
        <span>班次类型： ${cf:schTypeName(order.schType) } </span>
        <span> 班次: ${order.regBusNo} </span>
        <span> 车型: ${order.busTypeName} </span>
      </div>
      <div id="s-information">
        <div id="start-information">
          <span class="b-font"> ${order.startStationName} </span>
        </div>
        <div id="d-information">
          <span id="time-information">${order.leaveTime}</span>
          <span id="calendar-information">${order.leaveDate}</span>
        </div>
        <div id="arrive-information">
          <span class="b-font"> ${order.arriveStationName} </span>
        </div>
      </div>
      <div class="f-information">
        <span>车票数量</span>
      </div>
      <c:if test="${order.adultnum!=0}">
        <a href="javascript:void(0);">
          <div id="w-bg">
            <span>
              <img src="${ctx}/images/card.png" width="33" height="21">
            </span>
            <span class="number-information">
                            成人票
              <span id="adultnum">${order.adultnum}</span>
                            张
            </span>
            <div class="price-inforamction">
              <span class="s-font-14">￥</span>
              ${order.price}
              <span class="s-font-14-1">/张</span>
            </div>
            <span class="more">
              <!--  <img src="${ctx}/images/more-icon.png" width="14" height="25">-->
              <img src="${ctx}/images/more-icon.png" class="img-4">
            </span>
          </div>
        </a>
      </c:if>
      <c:if test="${order.childnum!=0}">
        <a href="javascript:void(0);">
          <div id="w-bg">
            <span>
              <img src="${ctx}/images/card.png" width="33" height="21">
            </span>
            <span class="number-information">
                            儿童票
              <span id="childnum">${order.childnum}</span>
                             张
            </span>
            <div class="price-inforamction">
              <span class="s-font-14">￥</span>
              ${order.halfPrice}
              <span class="s-font-14-1">/张</span>
            </div>
            <span class="more">
              <!--  <img src="${ctx}/images/more-icon.png" width="14" height="25">-->
              <img src="${ctx}/images/more-icon.png" class="img-4">
            </span>
          </div>
        </a>
      </c:if>
      <c:if test="${order.specialnum!=0}">
        <a href="javascript:void(0);">
          <div id="w-bg">
            <span>
              <img src="${ctx}/images/card.png" width="33" height="21">
            </span>
            <span class="number-information">
                            军残票
              <span id="specialnum">${order.specialnum}</span>
                            张
            </span>
            <div class="price-inforamction">
              <span class="s-font-14">￥</span>
              ${order.halfPrice}
              <span class="s-font-14-1">/张</span>
            </div>
            <span class="more">
              <!--  <img src="${ctx}/images/more-icon.png" width="14" height="25">-->
              <img src="${ctx}/images/more-icon.png" class="img-4">
            </span>
          </div>
        </a>
      </c:if>
      <c:if test="${order.freenum!=0}">
        <a href="javascript:void(0);">
          <div id="w-bg">
            <span>
              <img src="${ctx}/images/card.png" width="33" height="21">
            </span>
            <span class="number-information">
                           免票
              <span id="freenum">${order.freenum}</span>
                            张
            </span>
            <div class="price-inforamction">
              <span class="s-font-14">￥</span>
              0.00
              <span class="s-font-14-1">/张</span>
            </div>
            <span class="more">
              <!--  <img src="${ctx}/images/more-icon.png" width="14" height="25">-->
              <img src="${ctx}/images/more-icon.png" class="img-4">
            </span>
          </div>
        </a>
      </c:if>
      <!-- 是否购买保险选择 -->
      <c:if test="${order.fullInsurance != constant.zero_double}">
        <div>
          <div id="w-bg">
            <span>
              <img src="${ctx}/images/icon-4.png" width="33" height="36">
            </span>

            <span class="number-information">购买保险</span>
            <div class="price-inforamction" style="width: 45%;">
              <input type="checkbox" id="hasinsurance" checked="checked" value="1" name="hasinsurance" <c:if test="${isForceSaleInsurance }">disabled="disabled"</c:if> />
            </div>
          </div>
        </div>
      </c:if>

      <c:if test="${order.fullServicePrice != constant.zero_double}">
        <div id="showserviceprice" class="serviceprice" style="padding: 4pt 0pt 0pt 0pt;">
          <div>
            <span> </span>
            <span id="total-ps" style="" class="totprices">
              <span class="s-font-14-2">+&nbsp;&nbsp;￥</span>
              <span id="service"></span>
            </span>
          </div>
        </div>
      </c:if>

      <c:if test="${order.fullInsurance != constant.zero_double}">
        <div id="showfullinsurance" class="serviceprice" style="padding: 0pt;">
          <div>
            <span> </span>
            <span id="total-ps" style="" class="totprices">
              <span id="rmb_symbol" class="s-font-14-2">+&nbsp;&nbsp;￥</span>
              <span id="fullInsuranceprice"></span>
            </span>
          </div>
        </div>
      </c:if>

      <c:if test="${order.childnum !=0 || order.specialnum !=0}">
        <c:if test="${order.halfInsurance != constant.zero_double}">
          <div id="showhalfinsurance" class="serviceprice" style="padding: 0pt;">
            <div>
              <span> </span>
              <span id="total-ps" style="" class="totprices">
                <span class="s-font-14-2">+&nbsp;&nbsp;￥</span>
                <span id="halfInsuranceprice"></span>
              </span>
            </div>
          </div>
        </c:if>
      </c:if>

      <c:if test="${hasPrivilege == true}">
        <div id="showprivilege" class="serviceprice" style="padding: 0pt;">
          <div>
            <span> </span>
            <span id="total-ps" style="" class="totprices">
              <span class="s-font-14-2">-&nbsp;&nbsp;￥</span>
              <span id="privilegeamount"></span>
            </span>
          </div>
        </div>
      </c:if>

      <div id="total-price" style="height: 40pt; line-height: 40pt;">
        <div>
          <span> </span>
          <span id="total-p">
                        总价:
            <span class="s-font-14-2">￥</span>
            <span id="total"></span>
          </span>
        </div>
      </div>
      <c:if test="${order.fullInsurance != constant.zero_double}">
      <div id="Nticket-tip-1">
        <c:choose>
            <c:when test="${isShanXi == true || isBaoji == true}">
               <a href="${ctx}/faq/detail.do?ver=${appVer}&startStationId=${order.startStationId}&categoryId=005&categoryName=保险说明&origin=orderConfirmPage">保险说明</a>
            </c:when>
            <c:otherwise>
                <a href="${ctx}/faq/detail.do?ver=${appVer}&startStationId=${order.startStationId}&categoryId=005&categoryName=保险说明&origin=orderConfirmPage">保险说明</a>&nbsp;&nbsp;
                <a href="${ctx}/faq/detail.do?ver=${appVer}&startStationId=${order.startStationId}&categoryId=006&categoryName=乘客意外险条款&origin=orderConfirmPage">乘客意外险条款</a>
            </c:otherwise>
        </c:choose>
      </div>
      </c:if>
      <c:if test="${order.startStationId == constant.xa_startstation_id || order.startStationId == constant.xawsl_startstation_id}">
      <div id="Nticket-tip-1" style="color:#FF4500;">
                温馨提示：活动期间每张票免3元服务费。
      </div>
      </c:if>
    </div>
   <!-- 隐藏表单 -->
   <input type="hidden" name="startStationId" value="${order.startStationId}"/>
   <input type="hidden" name="arriveStationId" value="${order.arriveStationId}"/>
   <input type="hidden" name="leaveDate" value="${order.leaveDate}"/>
   <input type="hidden" name="leaveTime" value="${order.leaveTime}"/>
   <input type="hidden" name="regBusNoFoid" value="${order.regBusNoFoid}"/>
   <input type="hidden" name="regBusNo" value="${order.regBusNo}"/>
   <input type="hidden" name="price" value="${order.price}" id="price"/>
   <input type="hidden" name="halfPrice" value="${order.halfPrice}" id="halfPrice"/>
   <input type="hidden" name="fullStationCharge" value="${order.fullStationCharge}"/>
   <input type="hidden" name="halfStationCharge" value="${order.halfStationCharge}"/>
   <input type="hidden" name="schType" value="${order.schType}"/>
   <input type="hidden" name="busTypeName" value="${order.busTypeName}"/>
   <input type="hidden" name="startStationName" value="${order.startStationName}"/>
   <input type="hidden" name="arriveStationName" value="${order.arriveStationName}"/>

   <input type="hidden" name="totalprice" id="totalprice"/>
   <input type="hidden" name="totalserviceprice" id="totalserviceprice"/>
   <input type="hidden" name="adultnum" id="adultnumsub" value="${order.adultnum}"/>
   <input type="hidden" name="childnum" id="childnumsub" value="${order.childnum}"/>
   <input type="hidden" name="specialnum" id="specialnumsub" value="${order.specialnum}"/>
   <input type="hidden" name="freenum" id="freenumsub" value="${order.freenum}"/>
   <input type="hidden" name="fullTicketNum" id="fullTicketNum"/>
   <input type="hidden" name="halfTicketNum" id="halfTicketNum"/>
   <input type="hidden" name="freeTicketNum" id="freeTicketNum"/>
   <input type="hidden" name="refer" id="refer"/>
   <input type="hidden" name="fullServicePrice" id="fullServicePrice" value="${order.fullServicePrice}"/><!-- 全票服务费 -->
   <input type="hidden" name="halfServicePrice" id="halfServicePrice" value="${order.halfServicePrice}"/><!-- 半票服务费 -->
   <input type="hidden" name="ticketQueryURL" id="ticketQueryURL" value="${ticketQueryURL}"/>
   <input type="hidden" name="surplusfreeNum" id="surplusfreeNum" value="${order.surplusfreeNum}"/>
   <input type="hidden" name="lineTypeId" id="lineTypeId" value="${order.lineTypeId}"/>
   <input type="hidden" name="hasPrivilege" id="hasPrivilege" value="${hasPrivilege}"/>  
   <input type="hidden" name="fullInsurance" id="fullInsurance" value="${order.fullInsurance}">
   <input type="hidden" name="halfInsurance" id="halfInsurance" value="${order.halfInsurance}">
   <input type="hidden" name="hasNcStartStation" id="hasNcStartStation" value="${hasNcStartStation}">
   <input type="hidden" name="donatedInsurance" id="donatedInsurance" value="${order.donatedInsurance}">
<%--    <input type="hidden" name="hasServicePrice" id="hasServicePrice" value="${hasServicePrice}"> --%>
   <input type="hidden" id="isForceSaleInsurance" name="isForceSaleInsurance" value="${isForceSaleInsurance }"/>
  </form>
  <div id="big-button">
    <a href="javascript:void(0);">
      <div class="sumbit-1" id="ordersubmit">提交订单</div>
    </a>
  </div>
  <%@ include file="/WEB-INF/views/popup_alert.jsp"%>
  <script type="text/javascript" src="${ctx}/js/jquery.min.js?ver=${jquery_min_version}"></script>
  <!-- mergeTo:${ctx}/js/custom.min.js?ver=${custom_min_version} -->
  <script type="text/javascript" src="${ctx}/js/custom.js?ver=${custom_version}"></script>
  <!-- mergeTo -->
  <script type="text/javascript">
	  var adultnum = $("#adultnum").text();
	  var childnum = $("#childnum").text();
	  var specialnum = $("#specialnum").text();
	  var freenum = $("#freenum").text();
	  var price = $("#price").val();
	  var halfPrice = $("#halfPrice").val();
	  var fullServicePrice = $("#fullServicePrice").val();
	  var halfServicePrice = $("#halfServicePrice").val();
      var appVer = "${appVer}";
      var const_appver_nc = "${constant.appver_nc}";
      var const_appver_ylns = "${constant.appver_ylns}";
      
      var fullInsurance = $("#fullInsurance").val();
      var halfInsurance = $("#halfInsurance").val();
      
      var privilegeInsurance = "${constant.privilege_insurance}";
      var zeroDouble = "${constant.zero_double}";
      var hasNcStartStation = $("#hasNcStartStation").val();//是否是南充当代的出发站
      var donatedInsurance = $("#donatedInsurance").val();//减免的保险费
	  
      $(function(){
    	  
    	  var referordersubmit = ${constant.refer_ordersubmit};
    	  // 乘客数量默认值
    	  if(adultnum == ""){
    		  adultnum = 0;
    	  }
    	  if(childnum == ""){
    		  childnum = 0;
    	  }
    	  if(specialnum == ""){
    		  specialnum = 0;
    	  }
    	  if(freenum == ""){
    		  freenum = 0;
    	  }
    	  
    	  //计算半票数量
          var halfticketnum = parseInt(childnum) + parseInt(specialnum);
    	  //计算票总数
    	  var totalticketnum = parseInt(adultnum) + halfticketnum;
    	  // 分别计算不同类型乘客合计票价
    	  var adulttotal = parseFloat(adultnum) * parseFloat(price);
    	  var childtotal = parseFloat(childnum) * parseFloat(halfPrice);
    	  var speciatotal = parseFloat(specialnum) * parseFloat(halfPrice);
    	  var totalmoney = adulttotal + childtotal + speciatotal;
    	  //计算服务费的总价
          var totalfullserviceprice = parseFloat(adultnum) * parseFloat(fullServicePrice);
          var totalhalfserviceprice = parseFloat(halfticketnum) * parseFloat(halfServicePrice);
          var totalservice = parseFloat(totalfullserviceprice) + parseFloat(totalhalfserviceprice);
          //计算保险费
          var fullinsurance = parseFloat(adultnum) * parseFloat(fullInsurance);
          var halfinsurance = parseFloat(halfticketnum) * parseFloat(halfInsurance);
          var totinsurance = fullinsurance + halfinsurance;
    	  //计算全票和半票包含服务费和保险费价格
    	  var totalfullticketprice = adulttotal + totalfullserviceprice + fullinsurance;
          var totalhaleticketprice = childtotal + speciatotal + totalhalfserviceprice + halfinsurance; 
    	  var total = totalfullticketprice + totalhaleticketprice;
    	  //南充当代赠送的保费从总价中扣除
     	  if(donatedInsurance != zeroDouble){
     		  //计算减免的保费总价
     		  var totaldonatedInsurance = parseInt(adultnum) * parseFloat(donatedInsurance);
     		  total = total - totaldonatedInsurance;
     	  }

    	  $("#totalprice").val(total);
          var privilegeamount = "${constant.privilege_amount}";//优惠金额
          var hasPrivilege = $("#hasPrivilege").val(); // 是否有优惠标识
         // var hasServicePrice = $("#hasServicePrice").val();//是否有服务费
         
          if(fullServicePrice != zeroDouble){
        	  $("#service").html("服务费："+ fullServicePrice + "&nbsp;x&nbsp;" + totalticketnum);
          }

          if(fullInsurance != zeroDouble){
         	  if(donatedInsurance != zeroDouble){
         	      $("#rmb_symbol").html("￥");
         		  $("#fullInsuranceprice").html("赠送保险费: "+ donatedInsurance + "&nbsp;x&nbsp;" + adultnum);
         	  }else{
         	      $("#rmb_symbol").html("+&nbsp;&nbsp;￥");
        		  $("#fullInsuranceprice").html("保险费："+ fullInsurance + "&nbsp;x&nbsp;" + adultnum);
        	  }
          }
          
          if(halfInsurance != zeroDouble){
//               if(halfInsurance == privilegeInsurance && hasNcStartStation=="true"){
//                   $("#halfInsuranceprice").html("赠送保险费: "+ halfInsurance + "&nbsp;x&nbsp;" + halfticketnum);
//               }else{
                  $("#halfInsuranceprice").html("半票保险费 : "+ halfInsurance + "&nbsp;x&nbsp;" + halfticketnum);
              //}
          }
          //var totamount;
    	  if(hasPrivilege=="true"){
    		   var totprivilege = parseFloat(adultnum) * parseFloat(privilegeamount);
    		   total = total - totprivilege;
    		   $("#total").html(total.toFixed(2));
    		   $("#totalprice").val(total);
    		   $("#privilegeamount").html("优惠金额：" + privilegeamount + "&nbsp;x&nbsp;" + adultnum);
    	  }else{
    		  $("#total").html(total.toFixed(2));
    	  }
    	   
    	  $("#container").find("a").each(function(i){
    		  $(this).click(function(){
                  $("#adultnumsub").val(adultnum);
                  $("#childnumsub").val(childnum);
                  $("#specialnumsub").val(specialnum);
                  $("#freenumsub").val(freenum);
                  $("#form").attr("action","${ctx}/order/passengernum.do");
                  $("#form").submit();
              });
    	  });

          $("#ordersubmit").on("click",function(e){

            $("#fullTicketNum").val(adultnum);
            $("#halfTicketNum").val(halfticketnum);
            $("#freeTicketNum").val(freenum);  
            $("#totalserviceprice").val(totalservice);
            $("#refer").val(referordersubmit);
           
         
            //判断剩余免票数量是否大于所选数量
            var surplusfreeNum = $("#surplusfreeNum").val();
            if(parseInt(freenum) != 0){
                if(parseInt(surplusfreeNum) == 0){
                    openAlert("剩余免票数为0,不能购买免票");
                    return false;
                } else {
                    if(parseInt(surplusfreeNum) < parseInt(freenum)){
                        openAlert("剩余免票数量不足，请重新选择");
                        return false;
                    }
                }
            }

            $("#form").attr("action","${ctx}/order/submit.do");
            $("#form").submit();
          });

          $("#main-top-right").bind("click", function(){
              var link = "${ctx}/trafficline/index.do?ver=${appVer}" + "&startCityId=" + localStorage.startCityId + "&starting=" + localStorage.starting + "&startStationId=" + localStorage.startStationId + "&startStationsDisabled=" + localStorage.startStationsDisabled + "&groupId=" + localStorage.groupId;
              if (appVer == const_appver_nc || appVer == const_appver_ylns) {
                  link = "${ctx}/indexnc/index.do?ver=${appVer}"
              }
              window.location.href = link;
          });
          
          $("#hasinsurance").bind("click", function(){
        	  var hasChk = $('#hasinsurance').is(':checked');
        	  var insuranceTipsDiv = $("#Nticket-tip-1");
        	  if (hasChk) {
        		  $("#showfullinsurance").css("display","block");
                  $("#showhalfinsurance").css("display","block");
                  $("#total").html(total.toFixed(2));
                  $("#totalprice").val(total);
                  insuranceTipsDiv.slideDown(50);
        	  } else {
        		  $("#showfullinsurance").css("display","none");
                  $("#showhalfinsurance").css("display","none");
                  if(hasNcStartStation=="true"){
                	  if(donatedInsurance == zeroDouble){
	                       totalinsurances = total - totinsurance;
	                       $("#total").html(totalinsurances.toFixed(2));
	                       $("#totalprice").val(totalinsurances);
                	  }	  
                  }else{             	  
                      totalinsurances = total - totinsurance;
                      $("#total").html(totalinsurances.toFixed(2));
                      $("#totalprice").val(totalinsurances);
                  }
                  insuranceTipsDiv.slideUp(50);
        	  }
          });
      });
  </script>
</body>
</html>